import Vue, {DirectiveOptions} from 'vue'

import 'normalize.css'
import '@/styles/element-variables.scss'
import '@/styles/index.scss'
import '@/styles/size.scss'

import ElementUI from 'element-ui'
import SvgIcon from 'vue-svgicon'

import App from '@/App.vue'
import store from '@/store/store'
import {AppModule} from '@/store/modules/app'
import router from '@/router/router'
import i18n from '@/lang'
import '@/icons/components'
import '@/router/router_defend'
import '@/utils/error-log'
import $axios from '@/http'
import * as directives from '@/directives'
import * as filters from '@/utils/filter'
import {getOpenErrorLog, getOpenWarnLog} from "@/utils/storage";
import $K from "@/utils/kit";

Vue.use(ElementUI, {
    size: AppModule.size, // Set element-ui default size
    i18n: (key: string, value: string) => i18n.t(key, value)
});

Vue.use(v => {
    v.prototype.$axios = $axios;
    v.prototype.$K = $K;
});

Vue.use(SvgIcon, {
    tagName: 'svg-icon',
    defaultWidth: '1em',
    defaultHeight: '1em'
});

// 注册全局指令
Object.keys(directives).forEach(key => {
    Vue.directive(key, (directives as { [key: string]: DirectiveOptions })[key])
});

// 注册全局过滤功能
Object.keys(filters).forEach(key => {
    Vue.filter(key, (filters as any)[key])
});

Vue.config.productionTip = false;

// * 异常信息处理
Vue.config.errorHandler = function (err, vm, info) {
    if (getOpenErrorLog()) {
        console.log(`异常信息: ${err.toString()}\nInfo: ${info}  \n vm ${JSON.stringify(vm)}`);
    }
};
//警告信息处理
Vue.config.warnHandler = function (msg, vm, trace) {
    if (getOpenWarnLog()) {
        console.log(`友情提示信息: ${msg}\nTrace: ${trace}`);
    }
};


new Vue({
    router,
    store,
    i18n,
    render: (h) => h(App)
}).$mount('#app')
